package com.zhihuanbao.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zhihuanbao.business.domain.BizEnterpriseContacts;
import com.zhihuanbao.business.service.IBizEnterpriseContactsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhihuanbao.common.annotation.Log;
import com.zhihuanbao.common.core.controller.BaseController;
import com.zhihuanbao.common.core.domain.AjaxResult;
import com.zhihuanbao.common.enums.BusinessType;
import com.zhihuanbao.common.utils.poi.ExcelUtil;
import com.zhihuanbao.common.core.page.TableDataInfo;

/**
 * 企业联系人Controller
 * 
 * @author zhihuanbao
 * @date 2024-06-06
 */
@RestController
@RequestMapping("/business/contacts")
public class BizEnterpriseContactsController extends BaseController
{
    @Autowired
    private IBizEnterpriseContactsService bizEnterpriseContactsService;

    /**
     * 查询企业联系人列表
     */
    @PreAuthorize("@ss.hasPermi('business:contacts:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizEnterpriseContacts bizEnterpriseContacts)
    {
        startPage();
        List<BizEnterpriseContacts> list = bizEnterpriseContactsService.selectBizEnterpriseContactsList(bizEnterpriseContacts);
        return getDataTable(list);
    }

    /**
     * 导出企业联系人列表
     */
    @PreAuthorize("@ss.hasPermi('business:contacts:export')")
    @Log(title = "企业联系人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizEnterpriseContacts bizEnterpriseContacts)
    {
        List<BizEnterpriseContacts> list = bizEnterpriseContactsService.selectBizEnterpriseContactsList(bizEnterpriseContacts);
        ExcelUtil<BizEnterpriseContacts> util = new ExcelUtil<BizEnterpriseContacts>(BizEnterpriseContacts.class);
        util.exportExcel(response, list, "企业联系人数据");
    }

    /**
     * 获取企业联系人详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:contacts:query')")
    @GetMapping(value = "/{accountId}")
    public AjaxResult getInfo(@PathVariable("accountId") Long accountId)
    {
        return success(bizEnterpriseContactsService.selectBizEnterpriseContactsByAccountId(accountId));
    }

    /**
     * 新增企业联系人
     */
    @PreAuthorize("@ss.hasPermi('business:contacts:add')")
    @Log(title = "企业联系人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizEnterpriseContacts bizEnterpriseContacts)
    {
        return toAjax(bizEnterpriseContactsService.insertBizEnterpriseContacts(bizEnterpriseContacts));
    }
//    @PreAuthorize("@ss.hasPermi('business:contacts:add')")
//    @Log(title = "企业联系人", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody BizEnterprises bizEnterprises, SysUser sysUser)
//    {
//        BizEnterpriseContacts bizEnterpriseContacts = new BizEnterpriseContacts();
//        bizEnterpriseContacts.setContactPerson(sysUser.getNickName());
//        bizEnterpriseContacts.setContactUser(sysUser.getUserName());
//        return toAjax(bizEnterpriseContactsService.insertBizEnterpriseContacts(bizEnterpriseContacts));
//    }
    /**
     * 修改企业联系人
     */
    @PreAuthorize("@ss.hasPermi('business:contacts:edit')")
    @Log(title = "企业联系人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizEnterpriseContacts bizEnterpriseContacts)
    {
        return toAjax(bizEnterpriseContactsService.updateBizEnterpriseContacts(bizEnterpriseContacts));
    }

    /**
     * 删除企业联系人
     */
    @PreAuthorize("@ss.hasPermi('business:contacts:remove')")
    @Log(title = "企业联系人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{accountIds}")
    public AjaxResult remove(@PathVariable Long[] accountIds)
    {
        return toAjax(bizEnterpriseContactsService.deleteBizEnterpriseContactsByAccountIds(accountIds));
    }
}
